USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[TypeOfTrades-Insert]    Script Date: [[20120914065001]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065001]]
-- Description:	Insert record into table [dbo].[TypeOfTrades]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TypeOfTrades-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TypeOfTrades-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TypeOfTrades-Insert]
	/*@TypeOfTrade_RowNumber int =Null OUTPUT , 
	@TypeOfTrade_ID uniqueidentifier =Null  , 
	@TypeOfTrade_Code varchar(50) =Null  , 
	@TypeOfTrade_NameAr varchar(300) =Null  , 
	@TypeOfTrade_NameEn varchar(300) =Null  , 
	@TypeOfTrade_Notes varchar(max) =Null  , 
	@TypeOfTrade_Search varchar(max) =Null  , 
	@TypeOfTrade_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[TypeOfTrades](/*[TypeOfTrade_ID], [TypeOfTrade_Code], [TypeOfTrade_NameAr], [TypeOfTrade_NameEn], [TypeOfTrade_Notes], [TypeOfTrade_Search]*/)
	VALUES     (/*@TypeOfTrade_ID, @TypeOfTrade_Code, @TypeOfTrade_NameAr, @TypeOfTrade_NameEn, @TypeOfTrade_Notes, @TypeOfTrade_Search*/)

	/*SELECT @TypeOfTrade_RowNumber = [TypeOfTrade_RowNumber], @TypeOfTrade_TimeStamp = [TypeOfTrade_TimeStamp]
    FROM [dbo].[TypeOfTrades]
    WHERE  ( [TypeOfTrade_ID] =@TypeOfTrade_ID )
	AND  ( [TypeOfTrade_Code] =@TypeOfTrade_Code )
	AND  ( [TypeOfTrade_NameAr] =@TypeOfTrade_NameAr )
	AND  ( [TypeOfTrade_NameEn] =@TypeOfTrade_NameEn )
	AND  ( [TypeOfTrade_Notes] =@TypeOfTrade_Notes )
	AND  ( [TypeOfTrade_Search] =@TypeOfTrade_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[TypeOfTrades-update]    Script Date: [[20120914065001]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065001]]
-- Description:	Update record in table [dbo].[TypeOfTrades]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TypeOfTrades-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TypeOfTrades-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TypeOfTrades-update]
	/*@TypeOfTrade_RowNumber int =Null OUTPUT , 
	@TypeOfTrade_ID uniqueidentifier =Null  , 
	@TypeOfTrade_Code varchar(50) =Null  , 
	@TypeOfTrade_NameAr varchar(300) =Null  , 
	@TypeOfTrade_NameEn varchar(300) =Null  , 
	@TypeOfTrade_Notes varchar(max) =Null  , 
	@TypeOfTrade_Search varchar(max) =Null  , 
	@TypeOfTrade_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [TypeOfTrade_TimeStamp]
    FROM [dbo].[TypeOfTrades]
    	WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)

    IF  @OldTimeStamp = @TypeOfTrade_TimeStamp
    BEGIN*/
		Update [dbo].[TypeOfTrades] SET 
		/*[TypeOfTrade_ID] =@TypeOfTrade_ID, 
		[TypeOfTrade_Code] =@TypeOfTrade_Code, 
		[TypeOfTrade_NameAr] =@TypeOfTrade_NameAr, 
		[TypeOfTrade_NameEn] =@TypeOfTrade_NameEn, 
		[TypeOfTrade_Notes] =@TypeOfTrade_Notes, 
		[TypeOfTrade_Search] =@TypeOfTrade_Search*/
		/*WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)*/
	/*END*/

	/*SELECT @TypeOfTrade_RowNumber = [TypeOfTrade_RowNumber], @TypeOfTrade_TimeStamp = [TypeOfTrade_TimeStamp]
    FROM [dbo].[TypeOfTrades]
	WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[TypeOfTrades-Insert-Update]    Script Date: [[20120914065001]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065001]]
-- Description:	Insert OR Update record into table [dbo].[TypeOfTrades]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TypeOfTrades-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TypeOfTrades-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TypeOfTrades-Insert-Update]
	/*@TypeOfTrade_RowNumber int =Null OUTPUT , 
	@TypeOfTrade_ID uniqueidentifier =Null  , 
	@TypeOfTrade_Code varchar(50) =Null  , 
	@TypeOfTrade_NameAr varchar(300) =Null  , 
	@TypeOfTrade_NameEn varchar(300) =Null  , 
	@TypeOfTrade_Notes varchar(max) =Null  , 
	@TypeOfTrade_Search varchar(max) =Null  , 
	@TypeOfTrade_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[TypeOfTrades] 
					/*WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[TypeOfTrades](/*[TypeOfTrade_ID], [TypeOfTrade_Code], [TypeOfTrade_NameAr], [TypeOfTrade_NameEn], [TypeOfTrade_Notes], [TypeOfTrade_Search]*/)
		VALUES     (/*@TypeOfTrade_ID, @TypeOfTrade_Code, @TypeOfTrade_NameAr, @TypeOfTrade_NameEn, @TypeOfTrade_Notes, @TypeOfTrade_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [TypeOfTrade_TimeStamp]
		FROM [dbo].[TypeOfTrades]
    	WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)

		IF  @OldTimeStamp = @TypeOfTrade_TimeStamp
		BEGIN*/
			Update [dbo].[TypeOfTrades] SET 
			/*[TypeOfTrade_ID] =@TypeOfTrade_ID, 
			[TypeOfTrade_Code] =@TypeOfTrade_Code, 
			[TypeOfTrade_NameAr] =@TypeOfTrade_NameAr, 
			[TypeOfTrade_NameEn] =@TypeOfTrade_NameEn, 
			[TypeOfTrade_Notes] =@TypeOfTrade_Notes, 
			[TypeOfTrade_Search] =@TypeOfTrade_Search*/
			/*WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @TypeOfTrade_RowNumber = [TypeOfTrade_RowNumber], @TypeOfTrade_TimeStamp = [TypeOfTrade_TimeStamp]
    FROM [dbo].[TypeOfTrades]
	WHERE ([TypeOfTrade_ID] = @TypeOfTrade_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[TypeOfTrades-Delete]    Script Date: [[20120914065001]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065001]]
-- Description:	delete records from table [dbo].[TypeOfTrades] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TypeOfTrades-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TypeOfTrades-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TypeOfTrades-Delete]
	/*@TypeOfTrade_RowNumber int =null  , 
	@TypeOfTrade_ID uniqueidentifier =null  , 
	@TypeOfTrade_Code varchar(50) =null  , 
	@TypeOfTrade_NameAr varchar(300) =null  , 
	@TypeOfTrade_NameEn varchar(300) =null  , 
	@TypeOfTrade_Notes varchar(max) =null  , 
	@TypeOfTrade_Search varchar(max) =null  , 
	@TypeOfTrade_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[TypeOfTrades]
	WHERE /*( [TypeOfTrade_RowNumber] = ISNULL(@TypeOfTrade_RowNumber, [TypeOfTrade_RowNumber]) )
	AND ( [TypeOfTrade_ID] = ISNULL(@TypeOfTrade_ID, [TypeOfTrade_ID]) )
	AND ( [TypeOfTrade_Code] like ISNULL(@TypeOfTrade_Code, [TypeOfTrade_Code]) )
	AND ( [TypeOfTrade_NameAr] like ISNULL(@TypeOfTrade_NameAr, [TypeOfTrade_NameAr]) )
	AND ( [TypeOfTrade_NameEn] like ISNULL(@TypeOfTrade_NameEn, [TypeOfTrade_NameEn]) )
	AND ( [TypeOfTrade_Notes] like ISNULL(@TypeOfTrade_Notes, [TypeOfTrade_Notes]) )
	AND ( [TypeOfTrade_Search] like ISNULL(@TypeOfTrade_Search, [TypeOfTrade_Search]) )
	AND ( [TypeOfTrade_TimeStamp] = ISNULL(@TypeOfTrade_TimeStamp, [TypeOfTrade_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[TypeOfTrades-Select]    Script Date: [[20120914065001]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065001]]
-- Description:	select records from table [dbo].[TypeOfTrades] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TypeOfTrades-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TypeOfTrades-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TypeOfTrades-Select]
	/*@TypeOfTrade_RowNumber int =null  , 
	@TypeOfTrade_ID uniqueidentifier =null  , 
	@TypeOfTrade_Code varchar(50) =null  , 
	@TypeOfTrade_NameAr varchar(300) =null  , 
	@TypeOfTrade_NameEn varchar(300) =null  , 
	@TypeOfTrade_Notes varchar(max) =null  , 
	@TypeOfTrade_Search varchar(max) =null  , 
	@TypeOfTrade_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[TypeOfTrades]
	WHERE /*( [TypeOfTrade_RowNumber] = ISNULL(@TypeOfTrade_RowNumber, [TypeOfTrade_RowNumber]) )
	AND ( [TypeOfTrade_ID] = ISNULL(@TypeOfTrade_ID, [TypeOfTrade_ID]) )
	AND ( [TypeOfTrade_Code] like ISNULL(@TypeOfTrade_Code, [TypeOfTrade_Code]) )
	AND ( [TypeOfTrade_NameAr] like ISNULL(@TypeOfTrade_NameAr, [TypeOfTrade_NameAr]) )
	AND ( [TypeOfTrade_NameEn] like ISNULL(@TypeOfTrade_NameEn, [TypeOfTrade_NameEn]) )
	AND ( [TypeOfTrade_Notes] like ISNULL(@TypeOfTrade_Notes, [TypeOfTrade_Notes]) )
	AND ( [TypeOfTrade_Search] like ISNULL(@TypeOfTrade_Search, [TypeOfTrade_Search]) )
	AND ( [TypeOfTrade_TimeStamp] = ISNULL(@TypeOfTrade_TimeStamp, [TypeOfTrade_TimeStamp]) )*/
END
GO
-- =============================================
